package com.mybatis;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.runner.JUnitCore;

import java.util.HashMap;
import java.util.List;

public class Test extends JUnitCore {


    public static void main(String[] args) {
        SqlSession session = Util.getSession().openSession();
        UserDao userdao = session.getMapper(UserDao.class);
        User u = userdao.selectUserByID(5);
        System.out.println(u.getUserAddress());
        Logger log = Logger.getRootLogger();
        session.close();
        log.info("======");
    }

    @org.junit.Test
    public void testQueryUserByCondition() {
        SqlSession session = Util.getSession().openSession();

        try {
            HashMap<Object, Object> param = new HashMap<>();
            param.put("userName", "Spring");
            param.put("user", "user");
            List<User> objects = session.selectList("com.mybatis.UserDao.selectUserByCondition", param);
            System.out.println("objects = " + objects);
			if(objects!=null && objects.size()>0){
				System.out.println("user = " + objects.get(0).toString());;

			}

        } catch (Exception e) {
            System.out.println("e = " + e);
        } finally {
            session.close();
        }


    }


}
